<script lang="ts" setup>
import to from 'await-to-js'
import type { FormInstance } from 'element-plus'
import type { UserInfo, HandleType } from './data'
import OneUpload from '@/component/public/upload/OneUpload.vue'
import { editOperation } from '@/utils/data'

defineOptions({
  name: 'UserDetail'
})
const emit = defineEmits(['close'])
const props = defineProps<{
  currentRow: any | undefined
  type: HandleType
}>()
const title = '能力测试评审'
const isLoading = ref(false)
const ruleFormRef = ref<FormInstance>()
const dialogVisible = ref<boolean>(true)

const data = reactive({
  ruleForm: {
    betestedStatus: '已测试'
  },
  rules: {
    userId: [{ required: true, message: '请填写' }],
    roleIds: [{ required: true, message: '请选择' }]
  }
})
const { ruleForm, rules } = toRefs<any>(data)

const handleSubmit = async () => {
  const validate = await to(ruleFormRef.value.validate())
  if (!validate[1]) return
  const data = JSON.parse(JSON.stringify(ruleForm.value))
  isLoading.value = true
  const [err, res] = await to(editOperation(props.currentRow.abilityId, data))
  isLoading.value = false
  if (err) return
  ElMessage.success('操作成功')
  emit('close', true)
}

onMounted(() => {
  if (props.currentRow) {
    const data = JSON.parse(JSON.stringify(props.currentRow))
    // ruleForm.value = data
  }
})
</script>

<template>
  <el-dialog v-model="dialogVisible" :title="title" width="800px" class="one-dialog" draggable @close="emit('close')">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="140px"
      :disabled="type === 'detail'"
      class="mr-10 one-edit-form">
      <el-row :gutter="10">
        <el-col :lg="24" :span="24">
          <el-form-item label="审批状态:">
            <el-tag type="danger">待测试</el-tag>
          </el-form-item>
        </el-col>
        <el-col :lg="24" :span="24">
          <el-form-item label="能力测试报告上传:" prop="email">
            <OneUpload
              v-model="ruleForm.testFile1"
              v-model:name="ruleForm.testFileName1"
              :limit="1"
              :size="20"
              :types="['pdf', 'doc', 'docx', 'zip', 'rar', '7z', 'png']"></OneUpload>
            <div class="w-full text-xs text-slate-400">支持excel、world、txt等文件类型</div>
          </el-form-item>
        </el-col>
        <el-col :lg="24" :span="24">
          <el-form-item label="性能测试报告上传:" prop="email">
            <OneUpload
              v-model="ruleForm.testFile2"
              v-model:name="ruleForm.testFileName2"
              :limit="1"
              :size="20"
              :types="['pdf', 'doc', 'docx', 'zip', 'rar', '7z', 'png']"></OneUpload>
            <div class="w-full text-xs text-slate-400">支持excel、world、txt等文件类型</div>
          </el-form-item>
        </el-col>
        <el-col :lg="24" :span="24">
          <el-form-item label="其他资料上传:" prop="email">
            <OneUpload
              v-model="ruleForm.testFile3"
              v-model:name="ruleForm.testFileName3"
              :limit="1"
              :size="20"
              :types="['pdf', 'doc', 'docx', 'zip', 'rar', '7z', 'png']"></OneUpload>
            <div class="w-full text-xs text-slate-400">支持excel、world、txt等文件类型</div>
          </el-form-item>
        </el-col>
        <el-col :lg="24" :span="24">
          <el-form-item label="审核结果:" prop="betestedStatus">
            <el-radio-group v-model="ruleForm.betestedStatus">
              <el-radio label="已测试">通过</el-radio>
              <el-radio label="待测试">驳回</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :lg="24" :span="24">
          <el-form-item label="审批意见:" prop="testApproveComment">
            <el-input v-model="ruleForm.testApproveComment" type="textarea" placeholder="邮审批意见箱" class="w-full" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit()" :loading="isLoading">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
./data
